package com.database.findmystuff;

import java.io.Serializable;

/**
 * The user class, stores user information
 * 
 * @author Michael Azogu
 *
 */
public class User implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6693344135349714022L;
	private String email;
	private String password;
	private boolean isAdmin = false;
	private int attemptCounter = 0;
	
	/**
	 * The constructor
	 * 
	 * @param email The email of the user. Used as the user name.
	 * @param password It's a password. 
	 */
	public User(String email, String password){
		this.email = email;
		this.password = password;
	}
	
	/**
	 * Gets the user's email/username
	 * 
	 * @return Returns the email as a string
	 */
	public String getEmail(){
		return email;
	}
	
	/**
	 * Gets the password
	 * 
	 * @return The password.
	 */
	public String getPassword(){
		return password;
	}
	
	/**
	 * Gets the amount of incorrect login attempts made.
	 * 
	 * @return Returns the number of incorrect attempts
	 */
	public int getAttemptCounter(){
		return attemptCounter;
	}
	
	/**
	 * Changes the email if need be. Probably won't be used.
	 * 
	 * @param email The new email
	 */
	public void setEmail(String email){
		this.email = email;
	}
	
	/**
	 * Changes the password
	 * 
	 * @param password The password.
	 */
	public void setPassword(String password){
		this.password = password;
	}
	
	/**
	 * Changes whether or not the user is an administrator
	 * 
	 * @param isAdmin The value that determines if a user is an admin or not.
	 */
	public void setIsAdmin(boolean isAdmin){
		this.isAdmin = isAdmin;
	}
	
	/**
	 * Changes the user login attempts
	 * 
	 * @param newCount A new counter
	 */
	public void setAttemptCounter(int newCount){
		this.attemptCounter = newCount;
	}
	
	/**
	 * Changes the user login attempts to 0
	 */
	public void resetCounter(){
		this.attemptCounter = 0;
	}
	
	/**
	 * Increments the attempt counter 
	 */
	public void increaseCounter(){
		attemptCounter++;
	}
	/**
	 * returns it the isadmin field
	 * @return the value of isadmin
	 */
	public boolean getIsAdmin(){
		return isAdmin;
	}
	/**
	 * used to generate a custom hashcode based on the user's email and password
	 */
	@Override
	public int hashCode(){
		return email.hashCode() + password.hashCode();
	}
	
	/**
	 * used to compare two User objects and see if they are the same based on their hashcode
	 */
	@Override
	public boolean equals(Object o) {
	    if (o.hashCode()== this.hashCode()) {
	      return true;
	    }
	    return false;
	  }

}
